package pasantias.Dominio;

import java.util.ArrayList;
import java.util.List;

public class BoardMutable implements Board {

	protected final int width;
	protected final int height;
	
	
	private final List<Figura> figuras;

	public BoardMutable(int width, int height) {
		this.height = height;
		this.width = width;
		this.figuras = new ArrayList<Figura>();
	}

	@Override
	public String getDimensions() {
		return width + " " + height;
	}

	public boolean fits(Dot dot) {
		if (dot.getX() <= width && dot.getY() <= height) {
			return true;
		}
		return false;
	}


	public boolean fits(Rectangle rectangle) {
		if (rectangle.getVertex().getX() + rectangle.getWidth() <= width
				&& rectangle.getVertex().getY() + rectangle.getHeight() <= height) {
			return true;
		}
		return false;
	}

	public boolean fits(Circle circle) {
		int radius = circle.getRadius();
		Dot center = circle.getCenter();

		if (center.getX() + radius <= width && center.getX() - radius >= 0 && center.getY() + radius <= height
				&& center.getY() - radius >= 0) {
			return true;
		}
		return false;
	}

	public int getWidth() {
		return this.width;
	}

	public int getHeight() {
		return this.height;
	}
	
	public void addFigure(Circle circle) {
		if(this.fits(circle)) {
			figuras.add(circle);
		} else {
			throw new RuntimeException("The circle does not fit in the Board!!");
		}
	}

	public void addFigure(Rectangle rectangle){
		if(this.fits(rectangle)) {
			figuras.add(rectangle);
		} else {
			throw new RuntimeException("The rectangle does not fit in the Board!!");
		}
	}
	
	public void addFigure(Dot dot){
		if(this.fits(dot)) {
			figuras.add(dot);
		} else {
			throw new RuntimeException("The dot does not fit in the Board!!");
		}
	}
	
	public List<Figura> getFigures() {
		
		return figuras;
	}
}
